package interview.huawei.training.p45;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String name = null;
        int prettyDegree = 0;
        int[] counts = new int[26];

        for(int i = 0; i < n; i++) {
            name = scanner.nextLine();
            // 统计每个字母出现的次数
            Arrays.fill(counts, 0);
            for(int j = 0; j < name.length(); j++) {
                char ch = name.charAt(j);
                ch = Character.toLowerCase(ch);
                counts[ch - 'a']++;
            }
            Arrays.sort(counts);
            for (int j = 0, k = counts.length - 1; j < k; j++, k--) {
                int temp = counts[j];
                counts[j] = counts[k];
                counts[k] = temp;
            }
            prettyDegree = 0;
            for (int j = 0; j < counts.length && counts[j] > 0; j++) {
                prettyDegree += (26 - j) * counts[j];
            }
            System.out.println(prettyDegree);
        }
    }
}